package com.lx.huimailf.fragment.backorder;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.lx.huimailf.R;
import com.lx.huimailf.fragment.order.GiveProgressFragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * A simple {@link Fragment} subclass.
 */
public class BackProgressFragment extends Fragment {

    private ListView listView;
    private String status="";
    private TextView chaoshi;
    private Button tixing;
    TimeLineAdapter adapter;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_give_progress, container, false);

        listView = (ListView) view.findViewById(R.id.lv);
        chaoshi=(TextView)view.findViewById(R.id.chaoshi);
        tixing=(Button)view.findViewById(R.id.btn_tixing);
        listView.setDividerHeight(0);
        status=getActivity().getIntent().getStringExtra("status");
        if(status.equals("0")){
            adapter = new TimeLineAdapter(getActivity(), initData1());
            chaoshi.setVisibility(View.GONE);
            listView.setAdapter(adapter);
        }else if(status.equals("1")){
            adapter = new TimeLineAdapter(getActivity(), initData2());
            chaoshi.setVisibility(View.GONE);
            listView.setAdapter(adapter);

        }else if(status.equals("2")){
            adapter = new TimeLineAdapter(getActivity(), initData3());
            chaoshi.setVisibility(View.GONE);
            listView.setAdapter(adapter);

        }
        return view;
    }

    private List<Map<String, Object>> initData1(){
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("title", "订单已提交");
        map.put("time", "请耐心等待商家发货");
        list.add(map);

        return list;

    }
    private List<Map<String, Object>> initData2() {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("title", "订单已提交");
        map.put("time", "请耐心等待商家发货");
        list.add(map);

        map = new HashMap<String, Object>();
        map.put("title", "商品配送中");
        map.put("time", "请耐心等待配送");
        list.add(map);
        return list;

    }
    private List<Map<String, Object>> initData3() {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("title", "订单已提交");
        map.put("time", "请耐心等待商家发货");
        list.add(map);

        map = new HashMap<String, Object>();
        map.put("title", "商品配送中");
        map.put("time", "请耐心等待配送");
        list.add(map);

        map = new HashMap<String, Object>();
        map.put("title", "配送完成");
        map.put("time", "请确认收货");
        list.add(map);

        return list;

    }

    public class TimeLineAdapter extends BaseAdapter {
        private Context context;
        private List<Map<String, Object>> list;
        private LayoutInflater inflater;

        public TimeLineAdapter(Context context, List<Map<String, Object>> list) {
            super();
            this.context = context;
            this.list = list;
        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            TimeLineAdapter.TimeLineHolder viewHolder = null;
            if (convertView == null) {
                inflater = LayoutInflater.from(parent.getContext());
                convertView = inflater.inflate(R.layout.item_timeline, null);
                viewHolder = new TimeLineAdapter.TimeLineHolder();

                viewHolder.title = (TextView) convertView.findViewById(R.id.title);
                viewHolder.time = (TextView) convertView.findViewById(R.id.time);
                convertView.setTag(viewHolder);
            } else {
                viewHolder = (TimeLineAdapter.TimeLineHolder) convertView.getTag();
            }

            String titleStr = list.get(position).get("title").toString();
            String timeStr = list.get(position).get("time").toString();

            viewHolder.title.setText(titleStr);
            viewHolder.time.setText(timeStr);

            return convertView;

        }

        public class TimeLineHolder {
            private TextView title, time;
        }
    }

}